home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / KEYBOARD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-01  |  3.5 KB  |  147 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <MINTBIND.H>
  9. #include <OSBIND.H>
  10. #include <FILESYS.H>
  11. #include <MINTBIND.H>
  12. #include "XA_DEFS.H"
  13. #include "XA_TYPES.H"
  14. #include "XA_GLOBL.H"
  15. #include "APP_MAN.H"
  16. #include "C_WINDOW.H"
  17. #include "EVNT_MUL.H"
  18.  
  19. /*
  20.     Keyboard input handler
  21. */
  22.  
  23. void do_keyboard(void)
  24. {
  25.     long key;
  26.     unsigned short AESkey;
  27.     short shift_state;
  28.     XA_WINDOW *w=NULL;
  29.     XA_CLIENT *client;
  30.     short client_id;
  31.     short mx,my,mb,kstate;
  32.     unsigned long retv=XA_OK;
  33.     
  34.     vq_mouse(V_handle, &mb,&mx,&my);
  35.  
  36.     vq_key_s(V_handle,&shift_state);
  37.     kstate=shift_state;
  38.     
  39. #if ALT_CTRL_APP_OPS
  40. /* Check for control+alt+tab, and do an app swap if valid.... */
  41.     shift_state&=12;
  42.     if (shift_state==12)
  43.     {
  44.         key=Crawcin();
  45.         AESkey=(short)((key&0xff)|((key>>8)&0xff00));    /* translate the GEMDOS raw data into AES format*/
  46.  
  47.         switch(AESkey)
  48.         {
  49.             case 0xf09:            /* CTRL+ALT+TAB switches menu bars */
  50.                 next_app_menu();
  51.                 return;
  52.                 break;
  53.             case 0x1312:        /* Attempt to recover a hung system */
  54.                 recover();
  55.                 return;
  56.                 break;
  57.             case 0x260c:        /* Output a list of current clients via DIAGS */
  58.                 list_apps();
  59.                 return;
  60.                 break;
  61.             case 0x250b:        /* Tidy up after any clients that have died without calling appl_exit() */
  62.                 find_dead_clients();
  63.                 return;
  64.                 break;
  65.             case 0x2004:        /* Dump the current system status */
  66.                 status_dump();
  67.                 return;
  68.                 break;
  69.         }
  70.     }
  71. #endif
  72.  
  73.     
  74. #if POINT_TO_TYPE
  75. /* Keyboard input goes to the application whose window is under the mouse */
  76.     w=wind_find(mx,my); 
  77.  
  78. /* If there is no window under the mouse, send to the top window instead */
  79.     if (!w)
  80.     {
  81.         w=window_list;
  82.     }else{
  83.         
  84.         if (!(w->owner->waiting_for&XAWAIT_KEY))    /* If window under mouse isn't waiting for keys, maybe the top window is? */
  85.             w=window_list;
  86.     }
  87. #else
  88.  
  89. /* Keyboard input always goes to the application whose window is on top */
  90.     w=window_list;
  91.     client_id=w->owner;
  92.     
  93. #endif
  94.  
  95.     if (update_lock)
  96.     {
  97.         client_id=update_lock;
  98.     }
  99.  
  100.     client=Pid2Client(client_id);
  101.  
  102.     if (!client)
  103.         return;
  104.  
  105.     DIAGS(("keyhandler:client_id=%d, window_owner=%d\n",client_id,w->owner));
  106.  
  107.     if ((w)&&(w->owner==client_id))
  108.     {
  109.         if (w->keypress)    /* Does the target window have a keypress handler callback? */
  110.         {
  111.             key=Crawcin();
  112.             AESkey=(short)((key&0xff)|((key>>8)&0xff00));    /* translate the GEMDOS raw data into AES format*/
  113.             (*(w->keypress))(w,AESkey);
  114.             return;
  115.         }
  116.     }
  117.  
  118.     Psemaphore(2,CLIENTS_SEMAPHORE,-1L);
  119.  
  120.     if (client->waiting_for&XAWAIT_KEY)    /* If the client owning the window was waiting for a keyboard event, send it */
  121.     {
  122.         key=Crawcin();
  123.         AESkey=(short)((key&0xff)|((key>>8)&0xff00));    /* translate the GEMDOS raw data into AES format*/
  124.  
  125.         if (client->waiting_for&XAWAIT_MULTI)    /* If the client is waiting on a multi, the response is  */
  126.         {                                                /* slightly different to the evnt_keybd() response. */
  127.             client->waiting_pb->intout[0]=MU_KEYBD;
  128.             client->waiting_pb->intout[1]=mx;
  129.             client->waiting_pb->intout[2]=my;
  130.             client->waiting_pb->intout[3]=mb;
  131.             client->waiting_pb->intout[4]=kstate;
  132.             client->waiting_pb->intout[5]=AESkey;
  133.             client->waiting_pb->intout[6]=0;
  134.             cancel_evnt_multi(client_id);
  135.         }else{
  136.             client->waiting_pb->intout[0]=AESkey;
  137.             client->waiting_for=0;    /* Now client isn't waiting for anything */
  138.         }
  139.         
  140.         Fwrite(client->clnt_pipe_wr,sizeof(unsigned long),&retv);    /* Write success to clients reply pipe to unblock the process */
  141.         
  142.     }
  143.         
  144.     Psemaphore(3,CLIENTS_SEMAPHORE,0L);
  145.  
  146. }
  147.